package com.zhixiang.xaec.action.system;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.system.DicDetail;
import com.zhixiang.xaec.entity.system.DicType;
import com.zhixiang.xaec.service.system.DicDetailService;
import com.zhixiang.xaec.service.system.DicTypeService;


@Controller
@Scope("prototype")
public class DicDetailAction extends BaseAction
{
    private static final long serialVersionUID = -7980619592374932471L;

    @Autowired
    private DicDetailService dicDetailService;
    
    @Autowired
    private DicTypeService dicTypeService;

    private DicDetail dicDetail;

    public String save(){
       String dic=getRequest().getParameter("dic");
        if("cswcdw".equals(dic)){
            DicType dt=dicTypeService.findByDic("参数误差单位");
            if(dt!=null){
                dicDetail.setDicType(dt);
            }else{
                setSuccess(false);
                setMsg("dicType为空，保存失败！");
               return SUCCESS;
            }
        }
        dicDetailService.save(dicDetail);
        return SUCCESS;
    }

    public String get()
    {
        String detailId=getRequest().getParameter("detailId");
        if (detailId != null && !"".equals(dicDetail))
        {
            setResult(dicDetailService.get(Long.valueOf(detailId)));
        }
        return SUCCESS;
    }

    public String list()
    {
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<DicDetail> localList = dicDetailService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(localList);
        return SUCCESS;
    }

    public String delete()
    {
        try
        {
            String ids[] = getRequest().getParameterValues("ids");
            Long[] longIds = String2Array.stringArrayToLongArray(ids);
            dicDetailService.remove(longIds);
        }
        catch (Exception e)
        {
            setSuccess(false);
            setMsg("删除字典明细失败");
        }

        return SUCCESS;
    }

    public DicDetail getDicDetail()
    {
        return dicDetail;
    }

    public void setDicDetail(DicDetail dicDetail)
    {
        this.dicDetail = dicDetail;
    }

}
